package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.Identity;
import com.xinhe.web.response.IdentityView;
import com.xinhe.web.service.IdentityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@Api(value = "实名认证", tags = {"实名认证"})
@RestController
@RequestMapping(value = {"/identity"}, produces = {"application/json;charset=UTF-8"})

public class IdentityController {
    @Autowired
    private IdentityService identityService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询实名认证")
    @RequestMapping({"/pageIdentity"})
    public QueryResults<IdentityView> pageIdentity(String queryWord, String checkStatus,
                                                   int pageNum, int pageSize) {
        return this.identityService.pageIdentity(queryWord,checkStatus,pageNum,pageSize);
    }
    @WebUsed
    @ApiOperation("重置实名认证")
    @PostMapping({"/updateIdentityStatus"})
    public Result updateIdentityStatus(Long id) {
        return this.identityService.updateIdentityStatus(id);
    }

    @ApiOperation(httpMethod = "POST", value = "保存实名认证")
    @RequestMapping({"/saveIdentity"})
    public Result saveIdentity(Long userId,String name,String card,String certificateFront,String certificateBack, String gender) {
        return this.identityService.saveIdentity(userId,name, card, certificateFront, certificateBack,  gender);
    }


    @ApiOperation(httpMethod = "POST", value = "实名认证审核")
    @RequestMapping({"/saveIdentityCheck"})
    public Result saveIdentityCheck(Set<Long> identityIds,String status,String remark) {
        return this.identityService.saveCheck(identityIds,status,remark);
    }

    @ApiOperation(httpMethod = "GET", value = "删除实名认证")
    @ApiImplicitParam(name = "identityId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteIdentity"})
    public Result deleteIdentity(Long identityId) {
        return this.identityService.delete(identityId);
    }
    @ApiOperation(httpMethod = "GET", value = "实名认证详情")
    @ApiImplicitParam(name = "identityId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailIdentity"})
    public Result<Identity> detailIdentity(Long identityId) {
        return this.identityService.findById(identityId);
    }

    @ApiOperation(httpMethod = "GET", value = "实名认证详情")
    @RequestMapping({"/findIdentityByUserId"})
    public Result<Identity> findIdentityByUserId(Long userId) {
        return identityService.findIdentityByUserId(userId);
    }

}
